package com.zh.note.huawei.onehundred.水仙花数2;

/**
 * @Author: zhanghuan
 * @date: 2023/8/30 09:37
 * @description: create it
 */

import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    public static LinkedList<Integer> resultLinklist = new LinkedList<>();

    // 判断是否水仙花数
    public static boolean isWaterNum(int num) {
        int a = num % 10;//获取个位
        int b = num / 10 % 10;//获取十位
        int c = num / 100;//获取百位
        return a * a * a + b * b * b + c * c * c == num;
    }

    //字符串变成ASCII码之和
    public static int getStringAsciiSum(String s) {
        int result = 0;
        for (char c : s.toCharArray()) {
            result += c;
        }
        return result;
    }

    public static void findData(String values, int number) {
        String subStrOne;
        String subStrTwo;
        for (int j = 1; j < values.length(); ++j) {
            subStrOne = values.substring(0, j);
            subStrTwo = values.substring(j);
            if (isWaterNum(getStringAsciiSum(subStrOne))) {
                if (isWaterNum(getStringAsciiSum(subStrTwo))) {
                    resultLinklist.add(number);
                } else {
                    findData(subStrTwo, number++);
                }
            }
        }
    }

    public static void main(String[] args) {
        try {
            int count = 2;
            Scanner scan = new Scanner(System.in);
            String value = scan.nextLine();
            if (value == null || value.length() == 0) {
                System.out.println("input error");
                return;
            }
            findData(value, count);

            int result = 0;
            if (1 < resultLinklist.size()) {
                result = -1;
            } else if (1 == resultLinklist.size()) {
                result = resultLinklist.get(0);
            }
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("input error");
        }
    }
}

